import axios from 'axios'
import useUserStore from '../store/user'

const request = axios.create({
    baseURL: import.meta.env.PROD ? '/api' : '/api',
    timeout: 5000
})


request.interceptors.request.use((config) => {
    const UserStore = useUserStore()
    if (UserStore.token) {
        config.headers = {
            Authorization: UserStore.token,
            ...config.headers
        }
    }
    return config
})

request.interceptors.response.use((res) => {
    return res
})

export default request